package com.yc.cloud.openai.service;

import com.yc.cloud.basic.exception.Asserts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class OpenAiServiceFactory {

    private final Map<String, OpenAiService> services;

    @Autowired
    public OpenAiServiceFactory(List<OpenAiService> serviceList) {
        // 创建一个标识到服务实例的映射
        services = new HashMap<>();
        for (OpenAiService service : serviceList) {
            services.put(service.getIdentifier(), service);
        }
    }

    public OpenAiService getService(String identifier) {
        // 根据标识获取服务实例
        OpenAiService service = services.get(identifier);
        if (service == null) {
            Asserts.fail("No OpenAiService found for " + identifier);
        }
        return service;
    }
}

